﻿using UnityEngine;

public class CardViewCreator : PersistentSingleton<CardViewCreator>
{
    private string path = "Prefabs/CardView/";

    public CardView CreateCardView(Card card, GameObject viewSlot)
    {
        // 根据传入的 Card 类型，得到类名
        string className = card.Title;
        string fullPath = path + className;

        CardView prefab = Resources.Load<CardView>(fullPath);
        Debug.Log($"Trying to load prefab at: {fullPath}");
        if (prefab == null)
        {
            Debug.LogError($"Prefab not found at path: Resources/{fullPath}");
            return null;
        }

        // 实例化预制体并挂到 viewSlot 下
        CardView CardView = Instantiate(prefab, viewSlot.transform);

        // 调用 Setup，传入 Card
        CardView.Setup(card);
        Debug.Log(CardView.card.ProNumber);
        return CardView;
    }
    public CardView CreateCardView(Card card, Transform viewSlot)
    {
        // 根据传入的 Card 类型，得到类名
        string className = card.Title;
        string fullPath = path + className;

        CardView prefab = Resources.Load<CardView>(fullPath);
        //Debug.Log($"Trying to load prefab at: {fullPath}");
        if (prefab == null)
        {
            //Debug.LogError($"Prefab not found at path: Resources/{fullPath}");
            return null;
        }

        // 实例化预制体并挂到 viewSlot 下
        CardView CardView = Instantiate(prefab, viewSlot.transform);

        // 调用 Setup，传入 CardData
        CardView.Setup(card);
        // Debug.Log(CardView.card.ProNumber);
        return CardView;
    }
}
